//
//  MessageProcessor.cpp
//  xyz
//
//  Created by jorsun on 14-3-14.
//
//

#include "MessageProcessor.h"
static Queue<BaseMessage*>* q=new Queue<BaseMessage*>();
MessageProcessor::MessageProcessor(){
   
}
MessageProcessor::~MessageProcessor(void)
{
}
void MessageProcessor::put(BaseMessage* message){
    q->push(message);
}
void* MessageProcessor::run(void *arg){
    while(true){
        if(q->size()>0){
            HandlerManager::getInstance()->execute(q->pop());
        }
    }
}
void MessageProcessor::start(){
    int err;
    pthread_t ntid;
    err = pthread_create(&ntid, NULL, MessageProcessor::run, NULL);
    if (err != 0)
        printf("can't create thread: %s\n", strerror(err));
}
